package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.SysPrintContentSettingQuery;
import com.jcfk.system.domain.dto.SysPrintContentSettingDTO;
import com.jcfk.system.service.SysPrintContentSettingService;

/**
 * 打印内容设置
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-01-09
 */
@Api(tags = {"打印内容设置管理"})
@RestController
@RequestMapping("printContentSetting")
public class SysPrintContentSettingController {
    @Autowired
    private SysPrintContentSettingService sysPrintContentSettingService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<SysPrintContentSettingQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询打印内容设置")
    @PostMapping("/queryByPage")
    @ResponseBody
    public RetPage<SysPrintContentSettingDTO> queryByPage(@RequestBody ReqPageParam<SysPrintContentSettingQuery> requestParam) {
        DataPage<SysPrintContentSettingDTO> page = new DataPage<SysPrintContentSettingDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            SysPrintContentSettingDTO.class);
        page = sysPrintContentSettingService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  打印内容设置
     * 根据id 查询详情
     */
    @ApiOperation("查询打印内容设置")
    @GetMapping("/get/{id}")
    @ResponseBody
    public RetResult<SysPrintContentSettingDTO> get(@PathVariable("id") String id) {
            SysPrintContentSettingDTO item = sysPrintContentSettingService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理打印内容设置
     */
    @ApiOperation("保存打印内容设置")
    @PostMapping("/save")
    @ResponseBody
    @RequestLogHeader(modular = "打印内容设置管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid SysPrintContentSettingDTO sysPrintContentSetting) {
        // 数据校验
        RetResult ret = sysPrintContentSettingService.isValid(sysPrintContentSetting);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(sysPrintContentSetting.getId())){
            // 新增
            sysPrintContentSettingService.insert(sysPrintContentSetting);
        } else{
            // 更新
            sysPrintContentSettingService.update(sysPrintContentSetting);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除打印内容设置
     */
    @ApiOperation("批量删除打印内容设置")
    @ResponseBody
    @PostMapping("/delete")
    @RequestLogHeader(modular = "打印内容设置管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody SysPrintContentSettingDTO sysPrintContentSetting) {
        return RetResult.ok(sysPrintContentSettingService.removeBigBatch(sysPrintContentSetting.getIds()));
    }



}
